package com.example.demo.domain;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.*;

/**
 * @Create: IntelliJ IDEA.
 * @Author: subtlman_ljx
 * @Date: 2022/11/02/17:17
 * @Description:
 */
public class T {
    private static final Logger LOGGER = LoggerFactory.getLogger(T.class);

    public static void main(String[] args) {
        String elec1 = "electriccity\":{\"10202206090001_04\":\"98.83\",\"10202206090001_05\":\"174.918\",\"10202206090001_06\":\"205.064\",\"10202206090001_07\":\"21.471\",\"10202206090001_07\":\"-22.048\"},\"power\":{\"10202206090001_04\":\"1.197\",\"10202206090001_05\":\"2.352\",\"10202206090001_06\":\"3.235\",\"10202206090001_07\":\"-0.171\"},\"Speed\":\"8\",\"irradiance\":\"10\",\"REPORTTIME\":\"1668061843\"}}]}";
        LOGGER.info("周期数据上报elec1的值:,{}",elec1);
        List<Map<String,String>> list = new ArrayList<>();
        String elec2 = elec1.substring(elec1.indexOf("{")+1, elec1.indexOf("}"));
        LOGGER.info("周期数据上报elec2的值:,{}",elec2);
        String[] splits = elec2.split(",");
        for (String split : splits) {
            HashMap<String, String> map = new HashMap<>();
            String[] split1 = split.split(":");
            map.put(split1[0].substring(1,split1[0].length()-1),split1[1].substring(1,split1[1].length()-1));
            list.add(map);
        }
        System.out.println(list);
        if (list!=null && !list.isEmpty()){
            LOGGER.info("周期数据上报listMap的值:{}",list);
            for (Map electricity:list) {
                for (Object obj : electricity.keySet()) {
                    System.out.println(obj);
                }
            }
        }
    }



//    public static void main(String[] args) {
//        // TODO 自动生成方法存根
//        List<Map<String,Object>> listMap1 = new LinkedList<Map<String,Object>>();
//        Map<String,Object> map = new HashMap<String, Object>();
//        map.put("date", 20121010);
//        listMap1.add(map);
//        map = new HashMap<String, Object>();
//        map.put("date", 20011213);
//        listMap1.add(map);
//        listMap1.add(map);
//        map = new HashMap<String, Object>();
//        map.put("date", 20130502);
//        listMap1.add(map);
//        System.out.println("原始"+listMap1);
//
//        List<Map<String,Object>> listMap2 = new LinkedList<Map<String,Object>>();
//        Set<Map> setMap = new HashSet<Map>();
//        for(Map<String,Object> map1 : listMap1){
//            if(setMap.add(map1)){
//                listMap2.add(map1);
//            }
//        }
//        System.out.println("去重"+listMap2);
//
//        Collections.sort(listMap2, new Comparator<Map<String,Object>>(){
//            @Override
//            public int compare(Map<String,Object> o1, Map<String,Object> o2){
//                return o1.get("date").toString().compareTo(o2.get("date").toString());
//                //默认升序
//                //return o2.get("date").toString().compareTo(o1.get("date").toString());  降序
//
//            }
//        });
//        System.out.println("排序:"+listMap2);
//    }

}
